//package com.example.mytestdemo.customviewbook.three.testcustomctrl;
//
//import android.content.Context;
//import android.util.AttributeSet;
//import android.view.View;
//import android.view.ViewGroup;
//
//public class CustomViewGroup extends ViewGroup {
//    public CustomViewGroup(Context context) {
//        super(context);
//    }
//
//    public CustomViewGroup(Context context, AttributeSet attrs) {
//        super(context, attrs);
//    }
//
//    public CustomViewGroup(Context context, AttributeSet attrs, int defStyleAttr) {
//        super(context, attrs, defStyleAttr);
//    }
//
//    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//        //测量子控件
//        measureChildren(widthMeasureSpec, heightMeasureSpec);
//
//        //获取当宽/高设为wrap_content时，此模式下的控件宽高
//        int height = 0, maxWidth = 0;
//        int count = getChildCount();
//        for (int i = 0; i < count; i++) {
//            View child = getChildAt(i);
//            int childWidth = child.getMeasuredWidth();
//            if (childWidth > maxWidth) {
//                maxWidth = childWidth;
//            }
//            int childHeight = child.getMeasuredHeight();
//            height += childHeight;
//        }
//
//        //在wrap_content模式下，设置控件宽高
//        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
//        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
//        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
//        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
//        if (widthMode == MeasureSpec.AT_MOST && heightMode == MeasureSpec.AT_MOST){
//            setMeasuredDimension(maxWidth,height);
//        }else if (widthMode == MeasureSpec.AT_MOST){
//            setMeasuredDimension(maxWidth,heightSize);
//        }else if (heightMode == MeasureSpec.AT_MOST){
//            setMeasuredDimension(widthSize,height);
//        }else {
//            setMeasuredDimension(widthMeasureSpec,heightMeasureSpec);
//        }
//    }
//
//    @Override
//    protected void onLayout(boolean changed, int l, int t, int r, int b) {
//        int top = 0;
//        int count = getChildCount();
//        for (int i = 0; i < count; i++) {
//            View child = getChildAt(i);
//            int childWidth = child.getMeasuredWidth();
//            int childHeight = child.getMeasuredHeight();
//            child.layout(0, top, childWidth, top + childHeight);
//            top += childHeight;
//        }
//    }
//}
